package ${package.ServiceImpl};

import com.likan.chqjtgc.commons.PageVo;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
@Transactional(rollbackFor = {Exception.class})
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Autowired
    private ${entity}Mapper baseMapper;

    @Override
    public IPage<${entity}> findListByPage(PageVo< ${entity}> page){
           Page<${entity}> pageInfo = new Page<>(page.getCurrent(), page.getSize());
       QueryWrapper<${entity}> wrapper = new QueryWrapper<>();
        //todo:构造查询参数 根据业务添加

       if (StringUtils.isNotBlank(page.getSortField())){
           wrapper.orderBy(true,0!=page.getDirection() ,page.getSortField());
       }else {
           wrapper.orderByDesc("id");
       }
        IPage<${entity}> iPage = baseMapper.selectPage(pageInfo, wrapper);
        return iPage;
    }

    @Override
    public Boolean add(${entity} ${entity?uncap_first}){
    <#--${entity?uncap_first}.setId(IdWorker.getId());-->
        baseMapper.insert(${entity?uncap_first});
        return true;
    }

    @Override
    public Boolean delete(Long id){
        baseMapper.deleteById(id);
        return true;
    }

    @Override
    public Boolean updateData(${entity} ${entity?uncap_first}){
        baseMapper.updateById(${entity?uncap_first});
        return true;
    }

    @Override
    public ${entity} findById(Long id){
        ${entity} ${entity?uncap_first} = baseMapper.selectById(id);
        return ${entity?uncap_first};
    }
}
</#if>
